//
//  DetailView.m
//  XWZ_News_Work
//
//  Created by penngshi on 16/1/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "DetailView.h"
//@property (nonatomic ,strong)UILabel *requeatLabel;
//
//@property (nonatomic ,strong)UILabel *answerLabel;
@implementation DetailView

- (instancetype) initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self createSubView];
    }
    
    return self;
}

- (void)createSubView {
    
    self.requeatLabel  = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 80, 30)];
    self.requeatLabel.font = [UIFont systemFontOfSize:15.0];
    [self addSubview:self.requeatLabel];
    
    
    self.answerLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.requeatLabel.frame.origin.x + self.requeatLabel.frame.size.width, self.requeatLabel.frame.origin.y, 100, 30)];
    self.answerLabel.font = [UIFont systemFontOfSize:15.0];
    [self addSubview:self.answerLabel];
    
    
    
//    self.superhostButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.superhostButton.frame = CGRectMake(self.answerLabel.frame.origin.x + self.answerLabel.frame.size.width + 70, self.requeatLabel.frame.origin.y - 5, 50, 30);
//    self.superhostButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
//    self.superhostButton.layer.cornerRadius = 2;
//      self.superhostButton.layer.borderWidth = 1.0;
//    self.superhostButton.layer.borderColor = [[UIColor redColor]CGColor];
//    self.superhostButton.backgroundColor = [UIColor redColor];
//    [self.superhostButton setTitle:@"最热" forState:UIControlStateNormal];
//    [self.superhostButton addTarget:self action:@selector(superhostButtonAction) forControlEvents:UIControlEventTouchUpInside];
//    [self addSubview:self.superhostButton];
//
//    
//    
//    self.supernewButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.supernewButton.frame = CGRectMake(self.superhostButton.frame.origin.x + self.superhostButton.frame.size.width, self.requeatLabel.frame.origin.y - 5, 50, 30);
//    self.supernewButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
//    self.supernewButton.layer.cornerRadius = 2;
//    self.supernewButton.layer.borderWidth = 1.0;
//    self.supernewButton.layer.borderColor = [[UIColor redColor]CGColor];
//    [self.supernewButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//    [self.supernewButton setTitle:@"最新" forState:UIControlStateNormal];
//    [self.supernewButton addTarget:self action:@selector(supernewButtonAction) forControlEvents:UIControlEventTouchUpInside];
//    [self addSubview:self.supernewButton];
    
    self.segmentC = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"最热", @"最新", nil]];
//    self.segmentC.selectedSegmentIndex = 0;

    //设置中心点, 改变位置不改变大小
     self.segmentC.frame =CGRectMake(self.answerLabel.frame.origin.x + self.answerLabel.frame.size.width + 70, self.requeatLabel.frame.origin.y - 5, 100, 30);
    [self.segmentC addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
 
//    [self addSubview:self.segmentC];
    
    
   
}
- (void)segmentAction:(UISegmentedControl *)sender
{
    if (0 == sender.selectedSegmentIndex) {
        [self.delegatehost hostMessage];
        NSLog(@"qweqwe");
    }
    
    if (1 == sender.selectedSegmentIndex) {
        NSLog(@"___________+++++++");
        [self.delegate lastMessage];
    }
    
    //防止UISegmentedControl被覆盖
    [self bringSubviewToFront:sender];

}
- (void)superhostButtonAction
{
    self.superhostButton.backgroundColor = [UIColor redColor];
    [self.superhostButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self.delegatehost hostMessage];
}
- (void)supernewButtonAction
{
    self.supernewButton.backgroundColor = [UIColor redColor];
     [self.supernewButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.delegate lastMessage];
}

@end
